/**
 * 台阶脚本
 * 
 * 判断台阶碰撞逻辑
 * 设置台阶掉落逻辑
 */

var com = require('Common');

cc.Class({
  extends: cc.Component,

  properties: {
    time: 0,
    isUsed: false,
    isStanding: false,
    isDowned: false,
  },

  // 开始碰撞,设置台阶已使用
  onCollisionEnter: function (other, self) {
    this.isUsed = true;
  },

  // 碰撞进行中控制
  onCollisionStay: function (other, self) {
    this.isStanding = true;
  },

  // 碰撞结束时,控制掉落逻辑
  onCollisionExit: function (other, self) {
    if (com.gameIsStart) {
      this.isStanding = false;
      this.scheduleOnce(function () {
        this.stairIsUsed();
      }, 0.5);
    }
  },

  stairIsUsed: function () {
    if (com.gameIsStart) {
      var goAction = cc.moveBy(1.0, cc.v2(0, -600));
      this.node.runAction(goAction);
      setTimeout(() => {
        if (cc.isValid(this.node)) {
          this.node.destroy();
        }
      }, 1200);
    }
  },
});
